﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using BookStores.DTO;
using BookStores.DTO.Request;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using QuickFramework.Orm;

namespace QuickFramework.UICore.Controllers.Books
{
    /// <summary>
    /// 图书相关
    /// </summary>
    [Area("Books")]
    public class BookController : Shared.Contracts.AuthorizeControllerBase
    {
        BookStores.IDomain.IBooks m_IBooks;
        /// <summary>
        /// 
        /// </summary>
        public BookController(BookStores.IDomain.IBooks iBooks)
        {
            m_IBooks = iBooks;
        }
        /// <summary>
        /// 获取图书信息
        /// url: /api/Books/Book/Get
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Get(string id)
        {
            return Ok(await m_IBooks.GetBookInfo(id));
        }
        /// <summary>
        /// 图书数据保存
        /// url: /api/Books/Book/Save
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Save(BookInfo bookInfo)
        {
            (bool, string) result = await m_IBooks.Save(bookInfo);
            var resultObj = new { Result = result.Item1, Msg = result.Item2 };
            return Ok(resultObj);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public IActionResult Delete()
        {
            return Ok();
        }
        /// <summary>
        /// 查询数据
        /// url: /api/Books/Book/Query
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Query(BookQueryParam param)
        {
            var result = await m_IBooks.Query(param);
            var obj = new
            {
                items = result.Item1,
                total = result.Item2
            };
            return Ok(obj);
        }
        /// <summary>
        /// 查询数据
        /// url: /api/Books/Book/Delete
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Delete(string id)
        {
            var result = await m_IBooks.Delete(id);
            return Ok(result);
        }
    }
}
